﻿CREATE PROCEDURE [acms].[PostMenu_Put]
	@PostVersionId int, 
	@MenuId int,
	@Included bit,
	@ConcurencyId rowversion,
	@ConcurencyIdOut rowversion output
	
AS
	if Exists(select null from PostMenu where PostVersionId = @PostVersionId and MenuId = @MenuID and Deleted = 0) begin
		update PostMenu
		set Included = @Included
		where PostVersionId = @PostVersionId and MenuId = @MenuID and ConcurencyId = @ConcurencyId
		if(@@RowCount = 0)
			return -100
	end
	else begin
		insert into PostMenu
			(PostVersionId, MenuId, Included)
		values
			(@PostVersionId, @MenuId, @Included)
		
	end
	
	select @ConcurencyIdOut = ConcurencyId from PostMenu_View where PostVersionId = @PostVersionId and MenuId = @MenuID
RETURN 0;